Skip to content

Optimize CONCATENATE LINES OF runtime path - #1777

Merged
larshp merged 5 commits into
mainfrom
copilot/optimize-concatenate-lines-of
Jul 30, 2026
Merged

Optimize CONCATENATE LINES OF runtime path#1777
larshp merged 5 commits into
mainfrom
copilot/optimize-concatenate-lines-of

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

CONCATENATE LINES OF built an intermediate string[] for every row and then called join(), and re-evaluated respectingBlanks/separator conditions per row. The plain CONCATENATE path was already converted to direct string building in #1388; this applies the same treatment to the lines: true path.

Runtime (packages/runtime/src/statements/concatenate.ts)

  • Build the result string directly instead of array + join()
  • Index-based loop over tab.array() instead of an iterator
  • Hoist respectingBlanks and separator-presence checks out of the loop
let result = "";
const array = tab.array();
const respectingBlanks = input.respectingBlanks === true;
const hasSeparator = sep.length > 0;
for (let i = 0; i < array.length; i++) {
  if (hasSeparator === true && i > 0) {
    result += sep;
  }
  const value = array[i].get();
  result += respectingBlanks === true ? value : value.trimEnd();
}
input.target.set(result);

Behaviour is unchanged: separator only between lines, trailing blanks trimmed unless RESPECTING BLANKS, empty table yields an empty result.

Measurements

100k-row table of strings, 20 iterations:

case before after
no separator 186 ms 104 ms
SEPARATED BY 177 ms 84 ms
RESPECTING BLANKS 126 ms 17 ms

Tests

  • performance/test43.ts (+ registration): 43: CONCATENATE LINES OF
  • Unit tests for empty table, single line (no dangling separator), and a c LENGTH 5 table with/without separator

A trailing-whitespace fast path (skipping trimEnd() based on the last char code) was also benchmarked but regressed the trimming case, so it was left out.

Copilot AI linked an issue Jul 30, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Optimize concatenate lines of Optimize CONCATENATE LINES OF runtime path Jul 30, 2026
Copilot AI requested a review from larshp July 30, 2026 11:14
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

Regression test results:

Repository Result Runtime
abap-openapi/abap-openapi 🟢 21s
abapGit/abapGit 🟢 19s
heliconialabs/abap-opentelemetry 🟢 7s
heliconialabs/abap-protobuf 🟢 8s
larshp/abap-advent-2020 🟢 6s
larshp/abap-wasm 🟢 6s
larshp/abapNTLM 🟢 8s
larshp/abapPGP 🟢 164s
oisee/zork-abap 🟢 9s
open-abap/open-abap-core 🟢 8s
open-abap/open-abap-gui 🟢 7s
open-abap/open-abap-jobs 🟢 14s
open-abap/open-abap-lock 🟢 13s
open-abap/open-abap-odata 🟢 9s
open-abap/open-table-maintenance 🟢 17s
SAP/abap-file-formats-tools 🟢 20s
Sumu-Ning/AES 🟢 8s

Performance test results:

Performance Before After Delta
1: APPEND and DELETE 903ms 917ms 14 🟢
2: READ TABLE, table_line 1047ms 1048ms 1 🟢
3: LOOP USING KEY 1308ms 1316ms 8 🟢
4: Copy, same sorting 263ms 269ms 6 🟢
5: Copy, becomes sorted 62ms 61ms -1 🟢
6: INSERT INDEX 1 711ms 731ms 20 🟢
7: APPEND matching types 373ms 371ms -2 🟢
8: READ TABLE BINARY SEARCH 69ms 68ms -1 🟢
9: INSERT INTO TABLE hashed 376ms 377ms 1 🟢
10: DELETE ADJACENT 1535ms 1514ms -21 🟢
11: READ WITH TABLE KEY HASHED 266ms 271ms 5 🟢
12: READ WITH KEY HASHED, primary 367ms 370ms 3 🟢
13: INSERT INTO TABLE standard 38ms 36ms -2 🟢
14: Constant characters 72ms 71ms -1 🟢
15: Compare characters 119ms 118ms -1 🟢
16: Method number 5 🎶 804ms 828ms 24 🟢
17: Substring and find negative 275ms 262ms -13 🟢
18: CO compare 194ms 198ms 4 🟢
19: Call method, compatible structure 125ms 120ms -5 🟢
20: Call method, identical structure 21ms 20ms -1 🟢
21: CASE many char constants 353ms 364ms 11 🟢
22: READ TABLE WITH KEY secondary 46ms 51ms 5 🟢
23: CASE many int constants 366ms 379ms 13 🟢
24: Copy table contents 340ms 304ms -36 🟢
25: READ TABLE, not found 23ms 24ms 1 🟢
26: REPLACE OCCURRENCES, simple 142ms 139ms -3 🟢
27: READ TABLE, building hash 78ms 73ms -5 🟢
28: CONCATENATE 2ms 2ms 0 🟢
29: Write Hex to Hex via offset 1330ms 1332ms 2 🟢
30: Get Hex from Hex via offset 10ms 10ms 0 🟢
31: SET BIT hex 1342ms 1249ms -93 🟢
32: GET BIT hex 1108ms 980ms -128 🟢
33: Compare Hex 841ms 831ms -10 🟢
34: Basic CONCATENATE 71ms 70ms -1 🟢
35: gt 370ms 383ms 13 🟢
36: CLEAR char 266ms 266ms 0 🟢
37: CLEAR numc 246ms 246ms 0 🟢
38: Structure copy and APPEND 884ms 889ms 5 🟢
39: eq int 1404ms 1487ms 83 🟢
40: eq string 1217ms 1251ms 34 🟢
41: eq char, different lengths 223ms 212ms -11 🟢
42: eq int with numc 210ms 190ms -20 🟢
43: CONCATENATE LINES OF undefinedms 42ms NaN 🟢

Updated: 2026-07-30T11:55:46.302Z

SHA: d7060e1

@larshp
larshp marked this pull request as ready for review July 30, 2026 13:00
@larshp
larshp merged commit fc4ddbc into main Jul 30, 2026
4 of 5 checks passed
@larshp
larshp deleted the copilot/optimize-concatenate-lines-of branch July 30, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

optimize CONCATENATE LINES OF

2 participants